<?php 
	echo "冒泡排序<br/>";
	echo "倒序<br/>";
	$data = array('3','8','1','4','11','7');
	echo "<pre>";
	print_r($data);
	echo "</pre></br>";
	for ($i=1; $i < count($data); $i++) 
	{ 
		for ($j=count($data)-1; $j >= $i ; $j--) 
		{ 
			echo $data[$j]."-".$data[$j-1]."&nbsp;&nbsp;&nbsp;&nbsp;";
			if($data[$j]<$data[$j-1])
			{
				$x = $data[$j];
				$data[$j] = $data[$j-1];
				$data[$j-1] = $x;
			}
		}
	}
	echo "<pre>";
	print_r($data);
	echo "</pre></br>";

	echo "正序";
	$data2 = array('3','8','1','4','11','7');
	echo "<pre>";
	print_r($data2);
	echo "</pre></br>";
	for($i=1;$i<count($data2)-1;$i++)
	{
		for($j=0;$j<count($data2)-1;$j++)
		{
			echo $data2[$j]."-".$data2[$j+1]."&nbsp;&nbsp;&nbsp;&nbsp;";
			if($data2[$j]>$data2[$j+1])
			{
				$temp = $data2[$j+1];
				$data2[$j+1] = $data2[$j];
				$data2[$j] = $temp;
			}
		}
	}
	echo "<pre>";
	print_r($data2);
	echo "</pre></br>";
 ?>